package(default_visibility = ["//visibility:public",],)
# load("//bazel:prim.bzl", "COPTS", "PYX_COPTS", "PYX_SRCS", "copy_to_workspace")

config_setting(
    name = "msvc-cl",
    flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

config_setting(
    name = "clang-cl",
    flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"},
)

config_setting(
    name = "opt",
    values = {"compilation_mode": "opt"},
)

config_setting(
    name = "wolfssl",
    values = {"define": "ssl=wolfssl"},
)

config_setting(
   name = "openssl",
   values = {"define": "ssl=openssl"},
)

config_setting(
   name = "macos-build",
   values = {"define": "macos-build=true"},
)

config_setting(
   name = "microsoft-apsi",
   values = {"define": "microsoft-apsi=true"},
)

config_setting(
    name = "aarch64",
    values = {"define": "cpu_arch=aarch64"},
)

config_setting(
    name = "x86_64",
    values = {"define": "cpu_arch=x86_64"},
)
config_setting(
    name = "darwin_x86_64",
    values = {"define": "cpu_arch=darwin_x86_64"},
)

config_setting(
    name = "enable_mysql_driver",
    values = {"define": "enable_mysql_driver=true"},
)

DEFAULT_LINK_OPTS = [
    "-pthread",
    "-ldl",
]

DEFINES = [
    "ENABLE_FULL_GSL",
    "ENABLE_BOOST",
    "ENABLE_RELIC",
    "ENABLE_CIRCUITS",
    "ENABLE_NASM",
    "OC_ENABLE_PORTABLE_AES",
    "USE_JSON",
    "NDEBUG",
    "TEST_LIBP2P",
]

LINK_OPTS = select({
    ":wolfssl": DEFAULT_LINK_OPTS + ["-lwolfssl"],
    ":openssl": DEFAULT_LINK_OPTS + ["-lopenssl"],
    "//conditions:default": DEFAULT_LINK_OPTS,
})

LINK_PYTHON_OPTS = PLACEHOLDER-PYTHON3.X-CONFIG

C_OPT = [
    "-O0",
    "-g",
    "-Wall",
    "-ggdb",
    "-rdynamic",
    "-Wno-reserved-user-defined-literal",
] + select({
    ":x86_64": ["-maes", "-mpclmul"],
    ":aarch64": [],
    "//conditions:default": [],
})

## start of primihub
load("@com_github_grpc_grpc//bazel:grpc_build_system.bzl", "grpc_proto_library")

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
    name = "eigen",
    cache_entries = {
        "CMAKE_C_FLAGS": "-fPIC",
    },
    lib_source = "@eigen//:all_srcs",
    out_headers_only = True,
    includes = ["eigen3/",],
    install = True,
)

alias(
    name = "soralog",
    actual = "@soralog//:soralog",
)

# proto
grpc_proto_library(
    name = "route_guide",
    srcs = ["src/primihub/protos/route_guide.proto"],
)

grpc_proto_library(
    name = "worker_proto",
    srcs = ["src/primihub/protos/worker.proto"],
    deps = [
        ":common_proto",
        ":grpc_psi_proto",
        ":grpc_pir_proto",
    ],
)

grpc_proto_library(
    name = "common_proto",
    srcs = ["src/primihub/protos/common.proto"],
)

grpc_proto_library(
    name = "grpc_psi_proto",
    srcs = ["src/primihub/protos/psi.proto"],
)

grpc_proto_library(
    name = "grpc_pir_proto",
    srcs = ["src/primihub/protos/pir.proto"],
)


grpc_proto_library(
    name = "service_proto",
    srcs = ["src/primihub/protos/service.proto"],
)

cc_library(
    name = "server_config",
    hdrs = [
        "src/primihub/node/server_config.h",
    ],
    srcs = [
        "src/primihub/node/server_config.cc",
    ],
    deps = [
        ":config_lib",
        "@com_github_jbeder_yaml_cpp//:yaml-cpp",
    ],
)

cc_library(
    name = "microsoft_gsl",
    textual_hdrs = [
        "src/primihub/common/gsl/span",
        "src/primihub/common/gsl/gsl_assert",
        "src/primihub/common/gsl/gsl_util",
        "src/primihub/common/gsl/gsl_byte",
        "src/primihub/common/gsl/gsl_algorithm",
        "src/primihub/common/gsl/gsl",
        "src/primihub/common/gsl/multi_span",
        "src/primihub/common/gsl/string_span",
        "src/primihub/common/gsl/gls-lite.hpp",
    ],
    copts = C_OPT + [
        "--std=c++17",
    ],
    linkopts = LINK_OPTS,
)

cc_library(
    name = "common_defination",
    hdrs = [
        "src/primihub/common/common.h",
        "src/primihub/common/value_check_util.h",
    ],
)

cc_library(
    name = "config_lib",
    hdrs = [
        "src/primihub/common/config/config.h",
    ],
    srcs = [
        "src/primihub/common/config/config.cc",
    ],
    deps = [
        ":common_defination",
        "@com_github_jbeder_yaml_cpp//:yaml-cpp",
        "@com_github_glog_glog//:glog",
    ]
)

cc_library(
    name = "clp_lib",
    hdrs = [
        "src/primihub/common/clp.h",
    ],
    srcs = [
        "src/primihub/common/clp.cc",
    ],
    deps = [
        ":common_defination",
        ":microsoft_gsl",
    ],
)

cc_library(
    name = "eventbus_lib",
    hdrs = [
        "src/primihub/common/eventbus/eventbus.hpp",
        "src/primihub/common/eventbus/function_traits.hpp",
    ],
)
cc_library(
    name = "data_type_defination",
    hdrs = [
        "src/primihub/common/type/type.h",
        "src/primihub/common/type/fixed_point.h",
        "src/primihub/common/type/matrix.h",
        "src/primihub/common/type/matrix_view.h",
    ],
    srcs = [
        "src/primihub/common/type/type.cc",
        "src/primihub/common/type/fixed_point.cc",
    ],
    copts = C_OPT + [
        "--std=c++17",
    ],
    linkstatic = False,
    deps = [
        ":eigen",
        "@boost//:multiprecision",
        ":microsoft_gsl",
        ":common_util",
    ],
)

cc_library(
    name = "common_util",
    hdrs = [
        "src/primihub/common/defines.h",
    ],
    srcs = [
        "src/primihub/common/defines.cc",
    ],
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":microsoft_gsl",
        ":common_defination",
    ],
)
cc_library (
    name = "finally_tool",
    hdrs = [
        "src/primihub/common/finally.h",
    ],
)

cc_library(
    name = "common_lib",
    copts = C_OPT + [
        "--std=c++17",
    ],
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":common_defination",
        ":config_lib",
        ":common_util",
        ":clp_lib",
        ":eventbus_lib",
        ":finally_tool",
        ":data_type_defination",
        "@com_github_jbeder_yaml_cpp//:yaml-cpp",
        "@com_github_glog_glog//:glog",
    ],
)

cc_library(
    name = "share_lib",
    srcs = glob([
            "src/primihub/protocol/aby3/share.cc",
    ]),
    hdrs = glob([
            "src/primihub/protocol/aby3/share.h",
            "src/primihub/protocol/aby3/rand_ring_buffer.h",
    ]),
    textual_hdrs = [
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@boost//:fiber",
            "@boost//:multiprecision",
            "@boost//:asio",
            "@boost//:system",
            "@boost//:circular_buffer",
            "@boost//:variant",
            "@lib_function2//:function2",
            ":common_lib",
            ":prng_lib",
            ":network_lib",
        ],
)

cc_library(
    name = "endian_util",
    hdrs = [
        "src/primihub/util/endian_util.h",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
)

cc_library(
    name = "communication_lib",
    srcs = [
        "src/primihub/util/network/link_context.cc",
        "src/primihub/util/network/grpc_link_context.cc",
    ],
    hdrs = [
        "src/primihub/util/network/link_factory.h",
        "src/primihub/util/network/link_context.h",
        "src/primihub/util/network/grpc_link_context.h",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_github_glog_glog//:glog",
        "@com_github_grpc_grpc//:grpc++",
        ":config_lib",
        ":worker_proto",
    ],
)

cc_library(
  name = "network_lib",
  srcs = glob([
      "src/primihub/util/network/socket/commpkg.cc",
      "src/primihub/util/network/socket/acceptor.cc",
      "src/primihub/util/network/socket/channel_base.cc",
      "src/primihub/util/network/socket/channel.cc",
      "src/primihub/util/network/socket/chl_operation.cc",
      "src/primihub/util/network/socket/iobuffer.cc",
      "src/primihub/util/network/socket/ioservice.cc",
      "src/primihub/util/network/socket/session_base.cc",
      "src/primihub/util/network/socket/session.cc",
      "src/primihub/util/network/socket/tls.cc",
  ]),
  hdrs = glob([
      "src/primihub/util/network/socket/commpkg.h",
      "src/primihub/util/network/socket/acceptor.h",
      "src/primihub/util/network/socket/channel_base.h",
      "src/primihub/util/network/socket/channel.h",
      "src/primihub/util/network/socket/chl_operation.h",
      "src/primihub/util/network/socket/iobuffer.h",
      "src/primihub/util/network/socket/ioservice.h",
      "src/primihub/util/network/socket/session_base.h",
      "src/primihub/util/network/socket/session.h",
      "src/primihub/util/network/socket/socketadapter.h",
      "src/primihub/util/network/socket/tls.h",
  ]),
  copts = C_OPT,
  defines = DEFINES,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
          "@boost//:fiber",
          "@boost//:multiprecision",
          "@boost//:asio",
          "@boost//:system",
          "@boost//:circular_buffer",
          "@boost//:variant",
          ":common_lib",
          ":util_lib",
          ":crypto_lib",
      ],
)

cc_library(
  name = "protocol_base_lib",
  srcs = glob([
      "src/primihub/protocol/task.cc",
      "src/primihub/protocol/sh_task.cc",
      "src/primihub/protocol/scheduler.cc",
      "src/primihub/protocol/runtime.cc",
  ]),
  hdrs = glob([
      "src/primihub/protocol/task.h",
      "src/primihub/protocol/sh_task.h",
      "src/primihub/protocol/scheduler.h",
      "src/primihub/protocol/runtime.h",
  ]),
  copts = C_OPT,
  defines = DEFINES,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
          "@lib_function2//:function2",
          ":common_lib",
          ":util_lib",
          ":network_lib",
      ],
)

cc_library(
  name = "protocol_aby3_lib",
  srcs = glob([
      "src/primihub/protocol/aby3/evaluator/evaluator.cc",
      "src/primihub/protocol/aby3/evaluator/binary_evaluator.cc",
      "src/primihub/protocol/aby3/transpose.cc",
      "src/primihub/protocol/aby3/evaluator/piecewise.cc",
      "src/primihub/protocol/aby3/runtime.cc",
      "src/primihub/protocol/aby3/encryptor.cc",
  ]),
  hdrs = glob([
      "src/primihub/protocol/aby3/evaluator/evaluator.h",
      "src/primihub/protocol/aby3/evaluator/binary_evaluator.h",
      "src/primihub/protocol/aby3/evaluator/piecewise.h",
      "src/primihub/protocol/aby3/evaluator/converter.h",
      "src/primihub/protocol/aby3/transpose.h",
      "src/primihub/protocol/aby3/runtime.h",
      "src/primihub/protocol/aby3/encryptor.h",
      "src/primihub/protocol/aby3/sh3_gen.h",
  ]),
  copts = C_OPT,
  defines = DEFINES,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
          ":eigen",
          "@lib_function2//:function2",
          "@com_github_glog_glog//:glog",
          ":common_lib",
          ":protocol_base_lib",
          ":util_lib",
          ":primitive_lib",
          "crypto_lib",
      ],
)

cc_library(
  name = "protocol_cryptflow2_ot_lib",
  srcs = glob([
      "src/primihub/protocol/cryptflow2/*.cpp",
      "src/primihub/protocol/cryptflow2/BuildingBlocks/*.cpp",
      "src/primihub/protocol/cryptflow2/FloatingPoint/*.cpp",
      "src/primihub/protocol/cryptflow2/GC/*.cpp",
      "src/primihub/protocol/cryptflow2/LinearHE/*.cpp",
      "src/primihub/protocol/cryptflow2/LinearOT/*.cpp",
      "src/primihub/protocol/cryptflow2/Math/*.cpp",
      "src/primihub/protocol/cryptflow2/Millionaire/*.cpp",
      "src/primihub/protocol/cryptflow2/NonLinear/*.cpp",
      "src/primihub/protocol/cryptflow2/OT/*.cpp",
  ],
  exclude = [
    "src/primihub/protocol/cryptflow2/globals_float.cpp",
    "src/primihub/protocol/cryptflow2/library_float.cpp"]),
  hdrs = glob([
    "src/primihub/protocol/cryptflow2/*.h",
    "src/primihub/protocol/cryptflow2/utils/*.h",
    "src/primihub/protocol/cryptflow2/BuildingBlocks/*.h",
    "src/primihub/protocol/cryptflow2/FloatingPoint/*.h",
    "src/primihub/protocol/cryptflow2/GC/*.h",
    "src/primihub/protocol/cryptflow2/LinearHE/*.h",
    "src/primihub/protocol/cryptflow2/LinearOT/*.h",
    "src/primihub/protocol/cryptflow2/Math/*.h",
    "src/primihub/protocol/cryptflow2/Millionaire/*.h",
    "src/primihub/protocol/cryptflow2/NonLinear/*.h",
    "src/primihub/protocol/cryptflow2/OT/*.h",
    "src/primihub/protocol/cryptflow2/utils/*.hpp",
    "src/primihub/protocol/cryptflow2/GC/integer.hpp",
    "src/primihub/protocol/cryptflow2/GC/bit.hpp",
    "src/primihub/protocol/cryptflow2/utils/ArgMapping/*",
  ],
  exclude = ["src/primihub/protocol/cryptflow2/globals_float.h"]),
  linkstatic = False,
    copts = [
        "-I src/primihub/protocol/cryptflow2/",
        "-I src/primihub/protocol/cryptflow2/BuildingBlocks/",
        "-I src/primihub/protocol/cryptflow2/FloatingPoint/",
        "-I src/primihub/protocol/cryptflow2/GC/",
        "-I src/primihub/protocol/cryptflow2/LinearHE/",
        "-I src/primihub/protocol/cryptflow2/LinearOT/",
        "-I src/primihub/protocol/cryptflow2/Math/",
        "-I src/primihub/protocol/cryptflow2/Millionaire/",
        "-I src/primihub/protocol/cryptflow2/NonLinear/",
        "-I src/primihub/protocol/cryptflow2/OT/",
        "-I src/primihub/protocol/cryptflow2/utils/",
        "-D SCI_OT",
        "-pthread",
    ] + select({
        ":x86_64": ["-maes", "-msse4.1", "-mavx2", "-mrdseed",],
        ":aarch64": [],
        "//conditions:default": [],
    }),
    linkopts = ["-fopenmp"],
    deps = [
        "@com_microsoft_seal//:seal",
        "@com_github_gmp//:gmp",
        "@openssl",
        ":eigen",
    ]
)

cc_library(
    name = "protocol_falcon_lib",
    srcs = glob([
            "src/primihub/protocol/falcon-public/*.cpp",
            "src/primihub/protocol/falcon-public/util/*.cpp"
    ]),
    hdrs = glob([
            "src/primihub/protocol/falcon-public/*.h",
            "src/primihub/protocol/falcon-public/util/*.h",
	    "src/primihub/common/defines.h",
	    "src/primihub/common/gsl/*.h",
	    "src/primihub/common/gsl/*.hpp"
    ]),
    copts = [
	    # TODO: Consider to remove -I flag.
        "-I src/primihub/protocol/falcon-public/",
        "-I src/primihub/protocol/falcon-public/util/",
        "-fpic",
	    "-Wno-narrowing",
    ] + select({
        ":x86_64": ["-maes", "-mpclmul"],
        ":darwin_x86_64": ["-maes", "-mpclmul"],
        ":aarch64": [],
        "//conditions:default": [],
    }),
    linkstatic = False,
    deps = [
      ":eigen",
      "@openssl",
      ":common_util",
    ]
)

cc_library(
    name = "primitive_lib",
    srcs = glob([
        "src/primihub/primitive/ot/share_ot.cc",
        "src/primihub/primitive/circuit/garble.cc",
        "src/primihub/primitive/circuit/circuit_library.cc",
        "src/primihub/primitive/circuit/beta_circuit.cc",
        "src/primihub/primitive/circuit/beta_library.cc",
        "src/primihub/primitive/ppa/kogge_stone.cpp",
    ]),
    hdrs = glob([
        "src/primihub/primitive/ot/share_ot.h",
        "src/primihub/primitive/circuit/garble.h",
        "src/primihub/primitive/circuit/gate.h",
        "src/primihub/primitive/circuit/circuit_library.h",
        "src/primihub/primitive/circuit/beta_circuit.h",
        "src/primihub/primitive/circuit/beta_library.h",
        "src/primihub/primitive/ppa/kogge_stone.h",
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":eigen",
        "@nlohmann_json",
        ":common_lib",
        ":crypto_lib",
        ":network_lib",
    ],
)

cc_library(
    name = "cryptflow2_algorithm_lib",
    srcs = glob([
        "src/primihub/algorithm/cryptflow2_maxpool.cc",
    ]),
    hdrs = glob([
        "src/primihub/algorithm/base.h",
        "src/primihub/algorithm/cryptflow2_maxpool.h",
        "src/primihub/service/dataset/localkv/storage_default.h",
        "src/primihub/service/dataset/storage_backend.h",
	    "src/primihub/util/cpu_check.h"
    ]),
    copts = C_OPT + select({
        ":x86_64": ["-maes", "-mrdseed", "-mavx2"],
        ":aarch64": [],
        "//conditions:default": [],
    }),
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":eigen",
        ":common_lib",
        ":data_store_lib",
        ":dataset_service",
        ":protocol_cryptflow2_ot_lib",
    ],
)

cc_library(
    name = "algorithm_lib",
    srcs = glob([
            "src/primihub/algorithm/aby3ML.cc",
            "src/primihub/algorithm/linear_model_gen.cc",
            "src/primihub/algorithm/logistic.cc",
            "src/primihub/algorithm/logistic_plain.cc",
            "src/primihub/algorithm/plainML.cc",
            "src/primihub/algorithm/falcon_lenet.cc",
            "src/primihub/algorithm/arithmetic.cc",
            "src/primihub/executor/express.cc",
            "src/primihub/operator/aby3_operator.cc",
            "src/primihub/algorithm/missing_val_processing.cc",
    ]),
    hdrs = glob([
            "src/primihub/algorithm/base.h",
            "src/primihub/algorithm/aby3ML.h",
            "src/primihub/algorithm/linear_model_gen.h",
            "src/primihub/algorithm/logistic.h",
            "src/primihub/algorithm/logistic_plain.h",
            "src/primihub/algorithm/plainML.h",
            "src/primihub/algorithm/regression.h",
	        "src/primihub/algorithm/falcon_lenet.h",
            "src/primihub/service/dataset/localkv/storage_default.h",
            "src/primihub/service/dataset/storage_backend.h",
            "src/primihub/algorithm/arithmetic.h",
            "src/primihub/executor/express.h",
            "src/primihub/operator/aby3_operator.h",
            "src/primihub/algorithm/missing_val_processing.h",
    ]),
    copts = C_OPT + select({
        ":x86_64": ["-maes", "-mrdseed", "-msse4.1"],
        ":aarch64": [],
        "//conditions:default": [],
    }),
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":eigen",
        ":common_lib",
        ":protocol_aby3_lib",
        ":data_store_lib",
        ":model_util_lib",
        ":util_lib",
        ":dataset_service",
        ":protocol_falcon_lib"
    ],
)

cc_library(
    name = "mpc_express_executor",
    srcs = [
            "src/primihub/operator/aby3_operator.cc",
            "src/primihub/executor/express.cc",
    ],
    hdrs = [
            "src/primihub/executor/express.h",
            "src/primihub/common/type/type.h",
            "src/primihub/operator/aby3_operator.h",
            "src/primihub/common/type/fixed_point.h",
  ],
    deps = [
            ":protocol_aby3_lib",
            "@com_github_glog_glog//:glog"
  ],
    linkopts = LINK_OPTS,
)

cc_library(
    name = "aby3_operator",
    srcs = [
            "src/primihub/operator/aby3_operator.cc",
            "src/primihub/primitive/ppa/kogge_stone.h"
    ],
    hdrs = [
            "src/primihub/operator/aby3_operator.h",
            "src/primihub/common/type/type.h",
            "src/primihub/common/type/fixed_point.h",
            "src/primihub/primitive/ppa/kogge_stone.h"
    ],
    deps = [
            ":protocol_aby3_lib",
            "@com_github_glog_glog//:glog"
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
)

DEFAULT_TASK_LIB_DEPS = [
    "@com_github_glog_glog//:glog",
    "@com_github_grpc_grpc//:grpc++",
    "@com_google_absl//absl/base",
    "@com_google_absl//absl/flags:flag",
    "@com_google_absl//absl/flags:parse",
    "@com_google_absl//absl/memory",
    "@pybind11",
    ":util_lib",
    ":common_lib",
    ":algorithm_lib",
    "dataset_service",
    "notify_service",
    "@openssl",
    "@org_openmined_psi//private_set_intersection/cpp:psi_client",
    "@org_openmined_psi//private_set_intersection/cpp:psi_server",
    "@fmt//:fmt",
    #"@osu_libpsi//:libpsi",
]

PIR_LIB_DEPS = select({
    "microsoft-apsi": ["@mircrosoft_apsi//:APSI",],
    "//conditions:default": ["@org_openmined_pir//pir/cpp:pir"]
})


LINUX_X86_BUILD_LIBS = select({
    ":aarch64": [],
    ":x86_64":  [":cryptflow2_algorithm_lib", "@osu_libpsi//:libpsi"],
    ":darwin_x86_64": [],
    "//conditions:default": [],
})

TASK_LIB_DEPS = DEFAULT_TASK_LIB_DEPS + PIR_LIB_DEPS + LINUX_X86_BUILD_LIBS



cc_library(
    name = "task_lib",
    srcs = select({
        "microsoft-apsi": glob([
            "src/primihub/task/language/proto_parser.cc",
            "src/primihub/task/language/py_parser.cc",
            "src/primihub/task/semantic/psi_kkrt_task.cc",
            # "src/primihub/task/semantic/pir_server_task.cc",
            # "src/primihub/task/semantic/pir_client_task.cc",
            "src/primihub/task/semantic/parser.cc",
            "src/primihub/task/semantic/scheduler/mpc_scheduler.cc",
            "src/primihub/task/semantic/scheduler/aby3_scheduler.cc",
            "src/primihub/task/semantic/scheduler/psi_scheduler.cc",
            "src/primihub/task/semantic/scheduler/fl_scheduler.cc",
            "src/primihub/task/semantic/scheduler/tee_scheduler.cc",
            "src/primihub/task/semantic/scheduler/pir_scheduler.cc",
            "src/primihub/task/semantic/mpc_task.cc",
            "src/primihub/task/semantic/tee_task.cc",
            "src/primihub/task/semantic/task.cc",
            "src/primihub/task/semantic/private_server_base.cc",
            "src/primihub/task/semantic/fl_task.cc",
            "src/primihub/task/semantic/keyword_pir_client_task.cc",
            "src/primihub/task/semantic/keyword_pir_server_task.cc",
            "src/primihub/task/semantic/psi_ecdh_task.cc",
            "src/primihub/task/semantic/psi_task.cc",
            "src/primihub/task/semantic/task_context.cc",
         ]),
        "//conditions:default": glob([
            "src/primihub/task/language/proto_parser.cc",
            "src/primihub/task/language/py_parser.cc",
            "src/primihub/task/semantic/psi_kkrt_task.cc",
            "src/primihub/task/semantic/pir_server_task.cc",
            "src/primihub/task/semantic/pir_client_task.cc",
            "src/primihub/task/semantic/parser.cc",
            "src/primihub/task/semantic/scheduler/mpc_scheduler.cc",
            "src/primihub/task/semantic/scheduler/aby3_scheduler.cc",
            "src/primihub/task/semantic/scheduler/psi_scheduler.cc",
            "src/primihub/task/semantic/scheduler/fl_scheduler.cc",
            "src/primihub/task/semantic/scheduler/tee_scheduler.cc",
            "src/primihub/task/semantic/scheduler/pir_scheduler.cc",
            "src/primihub/task/semantic/mpc_task.cc",
            "src/primihub/task/semantic/tee_task.cc",
            "src/primihub/task/semantic/task.cc",
            "src/primihub/task/semantic/private_server_base.cc",
            "src/primihub/task/semantic/fl_task.cc",
            "src/primihub/task/semantic/psi_ecdh_task.cc",
            "src/primihub/task/semantic/psi_task.cc",
             "src/primihub/task/semantic/task_context.cc",
        ]),
    }),
    hdrs = select({
        "microsoft-apsi": glob([
            "src/primihub/task/language/proto_parser.h",
            "src/primihub/task/language/parser.h",
            "src/primihub/task/language/py_parser.h",
            "src/primihub/task/language/factory.h",
            "src/primihub/task/semantic/task.h",
            #"src/primihub/task/semantic/pir_server_task.h",
            "src/primihub/task/semantic/private_server_base.h",
            "src/primihub/task/semantic/parser.h",
            #"src/primihub/task/semantic/pir_client_task.h",
            "src/primihub/task/semantic/scheduler.h",
            "src/primihub/task/semantic/scheduler/pir_scheduler.h",
            "src/primihub/task/semantic/scheduler/fl_scheduler.h",
            "src/primihub/task/semantic/scheduler/mpc_scheduler.h",
            "src/primihub/task/semantic/scheduler/psi_scheduler.h",
            "src/primihub/task/semantic/scheduler/aby3_scheduler.h",
            "src/primihub/task/semantic/scheduler/tee_scheduler.h",
            "src/primihub/task/semantic/psi_kkrt_task.h",
            "src/primihub/task/semantic/keyword_pir_client_task.h",
            "src/primihub/task/semantic/keyword_pir_server_task.h",
            "src/primihub/task/semantic/factory.h",
            "src/primihub/task/semantic/mpc_task.h",
            "src/primihub/task/semantic/fl_task.h",
            "src/primihub/task/semantic/tee_task.h",
            "src/primihub/util/util.h",
            "src/primihub/task/semantic/psi_ecdh_task.h",
            "src/primihub/task/semantic/psi_task.h",
            "src/primihub/task/semantic/task_context.h",
        ]),
        "//conditions:default": glob([
            "src/primihub/task/language/proto_parser.h",
            "src/primihub/task/language/parser.h",
            "src/primihub/task/language/py_parser.h",
            "src/primihub/task/language/factory.h",
            "src/primihub/task/semantic/task.h",
            "src/primihub/task/semantic/pir_server_task.h",
            "src/primihub/task/semantic/private_server_base.h",
            "src/primihub/task/semantic/parser.h",
            "src/primihub/task/semantic/pir_client_task.h",
            "src/primihub/task/semantic/scheduler.h",
            "src/primihub/task/semantic/scheduler/pir_scheduler.h",
            "src/primihub/task/semantic/scheduler/fl_scheduler.h",
            "src/primihub/task/semantic/scheduler/mpc_scheduler.h",
            "src/primihub/task/semantic/scheduler/psi_scheduler.h",
            "src/primihub/task/semantic/scheduler/aby3_scheduler.h",
            "src/primihub/task/semantic/scheduler/tee_scheduler.h",
            "src/primihub/task/semantic/psi_kkrt_task.h",
            "src/primihub/task/semantic/factory.h",
            "src/primihub/task/semantic/mpc_task.h",
            "src/primihub/task/semantic/fl_task.h",
            "src/primihub/task/semantic/tee_task.h",
            "src/primihub/util/util.h",
            "src/primihub/task/semantic/psi_ecdh_task.h",
            "src/primihub/task/semantic/psi_task.h",
            "src/primihub/task/semantic/task_context.h",
        ]),
    }),
    copts = C_OPT + select({
        "microsoft-apsi" : ["-D_ASPI"],
        "//conditions:default": []
    }),
    defines = select({
        "microsoft-apsi" : [
            "USE_MICROSOFT_APSI",
        ],
        "//conditions:default": []
    }),
    # pre_build.sh use it to help locate line content of which need replace,
    # don't remove it.
    linkopts = LINK_OPTS + LINK_PYTHON_OPTS,
    linkstatic = False,
    deps = TASK_LIB_DEPS + [
        ":communication_lib",
        ":endian_util",
        ":server_config",
        "@boost//:process",
        "@com_github_base64_cpp//:base64_lib",
    ],
)

cc_library(
    name = "node_lib",
    srcs = glob([
        "src/primihub/node/worker/worker.cc",
        "src/primihub/algorithm/dataload.cpp",
    ]),
    hdrs = glob([
        "src/primihub/node/worker/worker.h",
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/memory",
        "@com_github_glog_glog//:glog",
        ":worker_proto",
        ":algorithm_lib",
        ":task_lib",
        ":network_lib",
        ":nodelet",
    ],
)

cc_library(
    name = "util_lib",
    srcs = glob([
              "src/primihub/util/util.cc",
              "src/primihub/util/log.cc",
              "src/primihub/util/timer.cc",
              "src/primihub/util/file_util.cc",
              "src/primihub/util/eigen_util.cc",
    ]),
    hdrs = glob([
              "src/primihub/util/util.h",
              "src/primihub/util/log.h",
              "src/primihub/util/timer.h",
              "src/primihub/util/file_util.h",
              "src/primihub/util/eigen_util.h",
              "src/primihub/util/threadsafe_queue.h",
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_github_grpc_grpc//:grpc++",
            "@com_github_glog_glog//:glog",
            "@boost//:asio",
            "@boost//:circular_buffer",
            ":worker_proto",
            ":common_lib",
    ],
)

cc_library(
    name = "model_util_lib",
    srcs = glob([
              "src/primihub/util/model_util.cc",
    ]),
    hdrs = glob([
              "src/primihub/util/model_util.h",
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_github_grpc_grpc//:grpc++",
            "@com_github_glog_glog//:glog",
            ":eigen",
            "@boost//:asio",
            "@boost//:circular_buffer",
            ":common_lib",
            ":prng_lib",
            ":util_lib",
    ],
)

cc_library(
    name = "crypto_lib",
    srcs = glob([
      "src/primihub/util/crypto/Blake2.cc",

      "src/primihub/util/crypto/blake2/c/blake2bp-ref.c",
      "src/primihub/util/crypto/blake2/c/blake2b-ref.c",
      "src/primihub/util/crypto/blake2/c/blake2sp-ref.c",
      "src/primihub/util/crypto/blake2/c/blake2s-ref.c",
      "src/primihub/util/crypto/blake2/c/blake2xb-ref.c",
      "src/primihub/util/crypto/blake2/c/blake2xs-ref.c",
      "src/primihub/util/crypto/blake2/sse/blake2b.c",
      "src/primihub/util/crypto/blake2/sse/blake2bp.c",
      "src/primihub/util/crypto/blake2/sse/blake2xb.c",
    ]),
    hdrs = glob([
      "src/primihub/util/crypto/hashable.h",
      "src/primihub/util/crypto/Blake2.h",
      "src/primihub/util/crypto/random_oracle.h",

      "src/primihub/util/crypto/blake2/c/blake2.h",
      "src/primihub/util/crypto/blake2/c/blake2-impl.h",
      "src/primihub/util/crypto/blake2/sse/blake2b-load-sse2.h",
      "src/primihub/util/crypto/blake2/sse/blake2b-load-sse41.h",
      "src/primihub/util/crypto/blake2/sse/blake2b-round.h",
      "src/primihub/util/crypto/blake2/sse/blake2-config.h",
      "src/primihub/util/crypto/blake2/sse/blake2.h",
      "src/primihub/util/crypto/blake2/sse/blake2-impl.h",
    ]),
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_github_grpc_grpc//:grpc++",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":util_lib",
            ":prng_lib",
    ],
)


cc_library(
    name = "prng_lib",
    srcs = glob([
      "src/primihub/util/crypto/aes/aes.cc",
      "src/primihub/util/crypto/aes/aes_dec.cc",
      "src/primihub/util/crypto/prng.cc",
      "src/primihub/util/crypto/bit_vector.cc",
      "src/primihub/util/crypto/block.cc",
    ]),
    hdrs = glob([
      "src/primihub/util/crypto/aes/aes.h",
      "src/primihub/util/crypto/aes/aes_dec.h",
      "src/primihub/util/crypto/aes/multikey_aes.h",
      "src/primihub/util/crypto/prng.h",
      "src/primihub/util/crypto/bit_iterator.h",
      "src/primihub/util/crypto/bit_vector.h",
      "src/primihub/util/crypto/block.h",
    ]),
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_github_grpc_grpc//:grpc++",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":util_lib",
    ],
)

# load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

cc_library(
    name = "data_store_lib",
    srcs = [
        "src/primihub/data_store/driver_legcy.cc",
        "src/primihub/data_store/driver.cc",
        "src/primihub/data_store/csv/csv_driver.cc",
        # "src/primihub/data_store/hdfs/hdfs_driver.cc",
        "src/primihub/data_store/sqlite/sqlite_driver.cc",
    ] + select({
        "enable_mysql_driver": [
            "src/primihub/data_store/mysql/mysql_driver.cc",
        ],
        "//conditions:default": []
    }),
    hdrs = [
        "src/primihub/data_store/factory.h",
        "src/primihub/data_store/dataset.h",
        "src/primihub/data_store/driver_legcy.h",
        "src/primihub/data_store/driver.h",
        "src/primihub/data_store/csv/csv_driver.h",
        #"src/primihub/data_store/hdfs/hdfs_driver.h",
        "src/primihub/data_store/sqlite/sqlite_driver.h",
    ] + select({
        "enable_mysql_driver": [
            "src/primihub/data_store/mysql/mysql_driver.h",
        ],
        "//conditions:default": []
    }),

    defines = select({
        "enable_mysql_driver": ["ENABLE_MYSQL_DRIVER"],
        "//conditions:default": []
    }),
    linkopts = LINK_OPTS + select({
        "enable_mysql_driver": ["-lmysqlclient"],
        "//conditions:default": []
    }),
    deps = [
        "@arrow",
        "@com_github_glog_glog//:glog",
        ":eigen",
        ":common_lib",
        ":crypto_lib",
        ":network_lib",
        ":util_lib",
        "@nlohmann_json",
        "@com_github_sqlite_wrapper//:sqlite_wrapper",
        "@com_github_jbeder_yaml_cpp//:yaml-cpp",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "new_data_store_lib",
    srcs = [
            "src/primihub/data_store/driver.cc",
            "src/primihub/data_store/csv/csv_driver.cc",
            # "src/primihub/data_store/hdfs/hdfs_driver.cc",
    ],
    hdrs = [
            "src/primihub/data_store/factory.h",
            "src/primihub/data_store/dataset.h",
            "src/primihub/data_store/driver.h",
            "src/primihub/data_store/csv/csv_driver.h",
            "src/primihub/data_store/hdfs/hdfs_driver.h",

    ],
    linkopts = LINK_OPTS,
    deps = [
        "@arrow",
        "@com_github_glog_glog//:glog",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "p2p_lib",
    srcs = [
            "src/primihub/p2p/node_stub.cc",
    ],
    hdrs = [
            "src/primihub/p2p/node_stub.h",
    ],
    linkopts = LINK_OPTS,
    deps = [
        "@libp2p//:p2p",
        "@boost//:thread",
    ],
    linkstatic = False,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "service_base",
    srcs = [
            "src/primihub/service/error.cpp",
    ],
    hdrs = [
            "src/primihub/service/error.hpp",
            "src/primihub/service/outcome.hpp",
            "src/primihub/service/outcome_reg.hpp",
    ],
    linkopts = LINK_OPTS,
    deps = [
        "@arrow",
        "@nlohmann_json",
        "@libp2p//:p2p",
        "@openssl",
        "@boost//:asio",
        "@boost//:thread",
        "@boost//:outcome",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)


cc_library(
    name = "dataset_service",
    srcs = [
            "src/primihub/service/dataset/model.cc",
            "src/primihub/service/dataset/service.cc",
            "src/primihub/service/dataset/localkv/storage_default.cc",
            "src/primihub/service/dataset/localkv/storage_leveldb.cc",
            "src/primihub/util/redis_helper.cc"
    ],
    hdrs = [
            "src/primihub/service/dataset/auth.h",
            "src/primihub/service/dataset/model.h",
            "src/primihub/service/dataset/service.h",
            "src/primihub/service/dataset/storage_backend.h",
            "src/primihub/service/dataset/localkv/storage_default.h",
            "src/primihub/service/dataset/localkv/storage_leveldb.h",
            "src/primihub/service/dataset/util.hpp",
            "src/primihub/util/redis_helper.h"
    ],
    linkopts = LINK_OPTS,
    deps = [
        "@com_github_glog_glog//:glog",
        "@com_github_google_leveldb//:leveldb",
        "@com_github_redis_hiredis//:hiredis",
        "@arrow",
        "@nlohmann_json",
        "@libp2p//:p2p",
        "@openssl",
        "@boost//:asio",
        "@boost//:thread",
        "@boost//:outcome",
        ":common_lib",
        ":p2p_lib",
        ":data_store_lib",
        ":util_lib",
        ":service_base",
        ":server_config",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)


cc_library(
    name = "notify_service",
    srcs = [
            "src/primihub/service/notify/model.cc",
            "src/primihub/service/notify/service.cc",
            "src/primihub/service/notify/model.h",
            "src/primihub/service/notify/service.h",
    ],
    hdrs = [
            "src/primihub/service/notify/model.h",
            "src/primihub/service/notify/service.h",
    ],
    copts = C_OPT + [
        "--std=c++17",
    ],
    linkopts = LINK_OPTS,
    deps = [
        "@com_github_glog_glog//:glog",
        "@com_github_grpc_grpc//:grpc++",
        "@boost//:outcome",
        ":service_proto",
        ":common_lib",
        ":service_base",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "nodelet",
    srcs = [
        "src/primihub/node/nodelet.cc",
    ],
    hdrs = [
        "src/primihub/node/nodelet.h",
    ],
    copts = C_OPT,
    linkstatic = False,
    linkopts = LINK_OPTS ,
    deps = [
        ":p2p_lib",
        ":dataset_service",
        ":notify_service",
    ],
)

########### pybind11 warppers start ########
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

pybind_extension(
    name = "primihub_channel",
    srcs = [
        "src/primihub/pybind_warpper/channel_warpper.cc",
    ],

    deps = [
        ":util_lib",
        ":network_lib",
    ],
)

py_library(
    name = "primihub_channel",
    data = ["primihub_channel.so"],
)

pybind_extension(
    name = "linkcontext",
    srcs = [
        "src/primihub/pybind_warpper/network/link_context_wrapper.cc",
    ],
    deps = [
        ":util_lib",
        ":communication_lib",
    ],
)

py_library(
    name = "linkcontext",
    data = ["linkcontext.so"],
)

pybind_extension(
    name = "pybind_mpc",
    srcs = [
        "src/primihub/pybind_warpper/express_wrapper.cc",
        "src/primihub/pybind_warpper/express_wrapper.h"
    ],
    deps = [
        ":mpc_express_executor"
    ],
)

pybind_extension(
    name = "primihub_dataset_warpper",
    srcs = [
            "src/primihub/pybind_warpper/dataset/dataset_warpper.cc",
            "src/primihub/pybind_warpper/dataset/dataset_warpper.hpp",
    ],
    deps = [
        "@arrow",
        ":dataset_service",
        ":data_store_lib",
    ],
)

py_library(
    name = "pybind_mpc",
    data = ["pybind_mpc.so"]
)

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")

proto_library(
    name = "proto_mpc_express_executor",
    srcs = ["python/primihub/protos/express.proto"],
)

py_proto_library(
    name = "py_proto_mpc_express_executor",
    deps = [":proto_mpc_express_executor"]
)

py_grpc_library(
    name = "py_mpc_express_grpc",
    srcs = [":proto_mpc_express_executor"],
    deps = [":py_proto_mpc_express_executor"]
)

py_library(
    name = "primihub_dataset_warpper",
    data = ["primihub_dataset_warpper.so"],
)


# cc_library(
#     name = "primihub_dataset_warpper",
#     srcs = [
#             "src/primihub/pybind_warpper/dataset/dataset_warpper.cc",
#     ],
#     hdrs = [
#             "src/primihub/pybind_warpper/dataset/dataset_warpper.hpp",
#     ],
#     copts = C_OPT,
#     linkstatic = False,
#     linkopts = LINK_OPTS + ["-L/Users/chb/miniforge3/lib -ldl -framework CoreFoundation"] + ["-lpython3.9"],
#     deps = [
#         "@arrow",
#         "@pybind11",
#         ":dataset_service",
#         ":data_store_lib",
#     ],
# )
########### pybind11 warppers end ########

cc_binary(
    name = "py_main",
    srcs = glob([
        "src/primihub/executor/py_executor.h",
        "src/primihub/executor/py_executor.cc",
    ]),
    linkopts = LINK_OPTS + LINK_PYTHON_OPTS,
    deps = [
        ":common_defination",
        ":worker_proto",
        "@pybind11",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/memory",
        "@com_github_glog_glog//:glog",
        "@com_github_base64_cpp//:base64_lib",
    ],
)

cc_binary(
    name = "node",
    srcs = glob([
        "src/primihub/node/node.cc",
        "src/primihub/node/node.h",
        "src/primihub/node/ds.cc",
        "src/primihub/node/ds.h",
        "src/primihub/node/main.cc",
    ]),
    copts = C_OPT,
    includes = [],
    linkstatic = True,
    linkopts = LINK_OPTS ,
    deps = [
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/memory",
        "@com_github_glog_glog//:glog",
        "@toolkit_relic//:relic",
        "@arrow",
        ":worker_proto",
        ":service_proto",
        ":common_lib",
        ":node_lib",
        ":nodelet",
        ":algorithm_lib",
        ":util_lib",
        ":server_config",
    ],
    data = [
        ":py_main",
    ],
)

cc_binary(
    name = "cli",
    srcs = [
        "src/primihub/cli/cli.cc",
        "src/primihub/cli/cli.h",
    ],
    copts = C_OPT,
    includes = [
    ],
    linkstatic = True,
    linkopts = LINK_OPTS,
    deps = [
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/memory",
        "@com_github_glog_glog//:glog",
        "@toolkit_relic//:relic",
        ":worker_proto",
        ":service_proto",
        ":common_lib",
        ":util_lib",
        "@openssl",
        "@com_github_stduuid//:stduuid_lib",
        ":communication_lib",
        "@nlohmann_json",
    ],
)

cc_binary(
    name = "reg_cli_test",
    srcs = [
        "src/primihub/cli/reg_cli.cc",
        "src/primihub/cli/reg_cli.h",
    ],
    copts = C_OPT,
    includes = [
    ],
    linkstatic = True,
    linkopts = LINK_OPTS,
    deps = [
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/memory",
        "@com_github_glog_glog//:glog",
        ":worker_proto",
        ":service_proto",
        "@openssl",
        "@com_github_stduuid//:stduuid_lib",
    ],
)
## end of primihub

## unit tests

cc_binary(
    name = "task_lib_test",
    srcs = [
        "test/primihub/task/fl_task_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":task_lib"
    ],
)


cc_test(
    name = "dataset_service_test",
    srcs = [
        "test/primihub/service/dataset/dataset_service_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@openssl",
        ":dataset_service",
        ":p2p_lib"
    ],
)

cc_binary(
    name = "notify_service_test",
    srcs = [
        "test/primihub/service/notify/notify_service_e2e_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = True,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":notify_service",
    ],
)

cc_binary (
    name = "notify_test_client",
    srcs = [
        "test/primihub/service/notify/test_client.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = True,
    deps = [
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_github_glog_glog//:glog",
        "@com_github_grpc_grpc//:grpc++",
        ":service_proto",
    ],
)


cc_test(
    name = "local_kv_test",
    srcs = [
        "test/primihub/service/dataset/local_kv_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":dataset_service",

    ],
)


cc_test(
    name = "common_test",
    srcs = [
        "test/primihub/common/type/type_test.cc",
        "test/primihub/common/type/fixed_point_test.cc"
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":common_lib",
    ],
)

cc_test(
    name = "primitive_test",
    srcs = [
        "test/primihub/primitive/ot/share_ot_test.cc",
        "test/primihub/primitive/circuit/circuit_test.cc"
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":primitive_lib",
    ],
)

cc_test(
    name = "logistic_test",
    srcs = ["test/primihub/algorithm/logistic_test.cc"],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
      "@com_google_googletest//:gtest_main",
      "@com_google_absl//absl/base",
      "@com_google_absl//absl/flags:flag",
      "@com_google_absl//absl/flags:parse",
      ":crypto_lib",
      ":algorithm_lib",
    ]
)

cc_test(
    name = "maxpool_test",
    srcs = ["test/primihub/algorithm/maxpool_test.cc"],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
      "@com_google_googletest//:gtest_main",
      "@com_google_absl//absl/base",
      "@com_google_absl//absl/flags:flag",
      "@com_google_absl//absl/flags:parse",
      "cryptflow2_algorithm_lib"
    ]
)
cc_test(
  name = "falcon_lenet_test",
  srcs=[
      "test/primihub/algorithm/falcon_lenet_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":crypto_lib",
        ":algorithm_lib",
     ],
)
# Some test case not in 'binary_evaluator_test.cc' will run into segment fault
# or error, so this rule will not build all test case.
cc_test(
    name = "protocol_aby3_test",
    srcs = [
      # "test/primihub/protocol/aby3/evaluator/evaluator_test.cc",
      "test/primihub/protocol/aby3/evaluator/binary_evaluator_test.cc",
      # "test/primihub/protocol/aby3/evaluator/piecewise_test.cc",
      # "test/primihub/protocol/aby3/encryptor_test.cc",
      # "test/primihub/protocol/aby3/runtime_test.cc",
      # "test/primihub/protocol/aby3/sh3_gen_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":protocol_aby3_lib",
    ],
)

cc_test(
  name = "aby3_div_test",
  srcs = [
    "test/primihub/algorithm/aby3_div_test.cc",
    "src/primihub/operator/aby3_operator.h",
    "src/primihub/operator/aby3_operator.cc",
  ],
  copts= C_OPT,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
    "@com_google_googletest//:gtest_main",
    ":network_lib",
    ":protocol_aby3_lib",
  ],
)


cc_test(
    name = "aby3_A2B_test",
    srcs = [
      # "test/primihub/protocol/aby3/evaluator/evaluator_test.cc",
      "test/primihub/algorithm/aby3_A2B_test.cc",
      # "test/primihub/protocol/aby3/evaluator/piecewise_test.cc",
      # "test/primihub/protocol/aby3/encryptor_test.cc",
      # "test/primihub/protocol/aby3/runtime_test.cc",
      # "test/primihub/protocol/aby3/sh3_gen_test.cc",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        ":protocol_aby3_lib",
    ],
)


cc_test(
  name = "aby3_add_test",
  srcs = [
    "test/primihub/algorithm/aby3_add_test.cc",
    "src/primihub/operator/aby3_operator.h",
    "src/primihub/operator/aby3_operator.cc",
  ],
  copts= C_OPT,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
    "@com_google_googletest//:gtest_main",
    ":network_lib",
    ":protocol_aby3_lib",
  ],
)

cc_test(
  name = "aby3_mul_test",
  srcs = [
    "test/primihub/algorithm/aby3_mul_test.cc",
    "src/primihub/operator/aby3_operator.h",
    "src/primihub/operator/aby3_operator.cc",
  ],
  copts= C_OPT,
  linkopts = LINK_OPTS,
  linkstatic = False,
  deps = [
    "@com_google_googletest//:gtest_main",
    ":network_lib",
    ":protocol_aby3_lib",
  ],
)

cc_test(
  name = "test_mpc_express_executor",
  srcs = [
    "test/primihub/executor/express_test.cc"
  ],
  copts = C_OPT,
  linkopts = LINK_OPTS,
  deps = [
    "@com_google_googletest//:gtest_main",
    ":mpc_express_executor"
  ]
)

cc_test(
        name = "aby3_MSB_test",
        srcs = [
                "test/primihub/algorithm/aby3_MSB_test.cc",
                "src/primihub/operator/aby3_operator.h",
                "src/primihub/operator/aby3_operator.cc",
        ],
        copts= C_OPT,
        linkopts = LINK_OPTS,
        linkstatic = False,
        deps = [
                "@com_google_googletest//:gtest_main",
                ":network_lib",
                ":protocol_aby3_lib",
        ],
)

cc_test(
    name = "mpc_cmp_test",
    srcs = [
        "test/primihub/operator/cmp_op_test.cc"
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_github_glog_glog//:glog",
        ":aby3_operator",
    ],
)

cc_test(
    name = "arrow_test",
    srcs = [
        "test/primihub/tmp/arrow_test.cc"
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_github_glog_glog//:glog",
        "@arrow",
        ":data_store_lib",
    ],
)


cc_test(
    name = "util_test",
    srcs = [
        #"test/primihub/util/model_util_test.cc",
        "test/primihub/util/eigen_util_test.cc",
    ],
    defines = ["BAZEL_BUILD"],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/base",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_github_glog_glog//:glog",
        ":util_lib",
        ":model_util_lib",
    ],
)

cc_test(
    name = "network_test",
    srcs = [
        "test/primihub/util/network/socket/channel_test.cc",
        "test/primihub/util/util_test.h",
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_google_googletest//:gtest_main",
            "@com_google_absl//absl/base",
            "@com_google_absl//absl/flags:flag",
            "@com_google_absl//absl/flags:parse",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":primitive_lib",
            ":network_lib",
            ":protocol_aby3_lib",
    ],
)

cc_test(
    name = "wolfssl_test",
    srcs = [
        "test/primihub/util/network/socket/wolfssl_test.cc",
        "test/primihub/util/test_util.h",
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_google_googletest//:gtest_main",
            "@com_google_absl//absl/base",
            "@com_google_absl//absl/flags:flag",
            "@com_google_absl//absl/flags:parse",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":primitive_lib",
            ":network_lib",
            ":protocol_aby3_lib",
    ],
)

cc_test(
    name = "prng_test",
    srcs = [
        "test/primihub/util/crypto/aes_test.cc",
        "test/primihub/util/crypto/prng_test.cc",
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_google_googletest//:gtest_main",
            "@com_google_absl//absl/base",
            "@com_google_absl//absl/flags:flag",
            "@com_google_absl//absl/flags:parse",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":prng_lib",
    ],
)


cc_test(
    name = "share_test",
    srcs = [
        "test/primihub/protocol/aby3/share_test.cc",
        "test/primihub/test_util.h",
    ],
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            "@com_google_googletest//:gtest_main",
            "@com_google_absl//absl/base",
            "@com_google_absl//absl/flags:flag",
            "@com_google_absl//absl/flags:parse",
            "@com_github_glog_glog//:glog",
            ":common_lib",
            ":network_lib",
            ":share_lib",
    ],
)




cc_library(
    name = "lib_miracl",
    srcs = glob(["thirdparty/miracl/mr_src/*.c"],),
    hdrs = glob(
      include = ["thirdparty/miracl/mr_include/*.h"],
    ),
    copts = C_OPT + ["-mdynamic-no-pic"],
    linkopts = LINK_OPTS,
    linkstatic = False,
    visibility = ["//visibility:public"],
)

######################### paillier start #########################
cc_library(
    name = "lib_paillier",
    srcs = glob(
        [
            "src/primihub/primitive/paillier/*.cpp",
        ],
    ),
    hdrs = glob([
        "src/primihub/primitive/paillier/*.h",
    ]),
    copts = C_OPT + ["-mdynamic-no-pic"],
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":lib_miracl",
    ],
    includes = ["thirdparty/miracl/mr_include"],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "paillier_test",
    srcs = [
        "test/primihub/primitive/paillier_test.cpp",
    ],
    includes = [
        "src/primihub/primitive/paillier"
    ],
    copts = C_OPT + ["-mdynamic-no-pic"],
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":lib_paillier",
    ],
)

cc_library(
    name = "lib_opt_paillier",
    srcs = glob(
        [
            "src/primihub/primitive/opt_paillier/src/*.cc",
        ],
    ),
    hdrs = glob([
        "src/primihub/primitive/opt_paillier/include/*.h",
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = True,
    deps = [
        "@com_github_gmp//:gmp",
    ],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "opt_paillier_test",
    srcs = [
        "test/primihub/primitive/opt_paillier_test.cc",
    ],
    includes = [
        "src/primihub/primitive/opt_paillier/include"
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":lib_opt_paillier",
    ],
)

cc_binary(
    name = "opt_paillier_pack_test",
    srcs = [
        "test/primihub/primitive/opt_paillier_pack_test.cc",
    ],
    includes = [
        "src/primihub/primitive/opt_paillier/include"
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":lib_opt_paillier",
    ],
)

pybind_extension(
    name = "opt_paillier_c2py",  # This name is not actually created!
    srcs = ["src/primihub/pybind_warpper/primitive/opt_paillier_c2py.cc",
            "src/primihub/pybind_warpper/primitive/opt_paillier_c2py.hpp",
    ],
    includes = [
        "src/primihub/primitive/opt_paillier/include"
    ],
    deps = [
        ":lib_opt_paillier",
    ],
)

py_library(
    name = "opt_paillier_c2py",
    data = ["opt_paillier_c2py.so"],
)

py_library(
    name = "opt_paillier_c2py_warpper",
    srcs = [
        "python/primihub/primitive/opt_paillier_c2py_warpper.py",
        "python/primihub/primitive/opt_paillier_pack_c2py_warpper.py"
        ],
    deps = [
        ":opt_paillier_c2py"
    ],
)

py_test(
    name = "test_opt_paillier_c2py",
    srcs = [
        "python/primihub/tests/test_opt_paillier_c2py.py"
    ],
    deps = [
        ":opt_paillier_c2py_warpper"
    ],
)

py_test(
    name = "test_opt_paillier_pack_c2py",
    srcs = [
        "python/primihub/tests/test_opt_paillier_pack_c2py.py"
    ],
    deps = [
        ":opt_paillier_c2py_warpper"
    ],
)

######################### paillier end #########################

cc_library(
    name = "libpsi_frontend",
    srcs = glob(
        [
            "test/primihub/protocol/libpsi/*.cc"
        ],
    ),
    hdrs = glob([
        "test/primihub/protocol/libpsi/*.h"
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = True,
    deps = TASK_LIB_DEPS,
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "libpsi_test",
    srcs = [
        "test/primihub/protocol/libpsi/libpsi.cc",
    ],
    includes = [
        "test/primihub/protocol/libpsi",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":libpsi_frontend"
    ],
)

cc_library(
    name = "kkrt_psi",
    srcs = glob(
        [
            "test/primihub/protocol/kkrtpsi/*.cc"
        ],
    ),
    hdrs = glob([
        "test/primihub/protocol/kkrtpsi/*.h"
    ]),
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = True,
    deps = [
        "@osu_libpsi//:libpsi",
    ],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "kkrt_psi_test",
    srcs = [
        "test/primihub/protocol/kkrtpsi/kkrtpsi.cc",
    ],
    includes = [
        "test/primihub/protocol/kkrtpsi",
    ],
    copts = C_OPT,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
        ":kkrt_psi"
    ],
)
# test
cc_test(
    name = "test",
    copts = C_OPT,
    defines = DEFINES,
    linkopts = LINK_OPTS,
    linkstatic = False,
    deps = [
            ":common_test",
            ":primitive_test",
            ":network_test",
            ":protocol_aby3_test",
            ":util_test",
            ":logistic_test",
            ":prng_test",
            ":share_test",
            ":opt_paillier_test",
    ],
)


genrule(
    name = "prim_pkg",
    srcs = [
        ":cp_redis",
    ],
    outs = ["primi_pkg.out"],
    cmd = """
        #if [ "$${OSTYPE-}" = "msys" ]; then
        #    ln -P -f -- python/ray/_raylet.so python/ray/_raylet.pyd
        #fi
        echo "$${PWD}" > $@
    """,
    local = 1,
)

